#! /bin/bash
#mysql_to_hdfs_full.sh all/表名 [日期]
#1、判断参数是否传入
if [ $# -lt 1 ]
then
	echo "必须传入all/表名..."
	exit
fi
#2、判断日期是否传入
[ "$2" ] && datestr=$2 || datestr=$(date -d '-1 day' +%F)

function load_data(){
	path=/origin_data/medical/$1/${datestr}
	#判断hdfs目录是否存在，如果不存在则创建目录
	hdfs dfs -test -e ${path}
	if [ $? -eq 1 ]
	then
		hdfs dfs -mkdir -p ${path}
	fi
		python /opt/module/datax/bin/datax.py -p"-Dtargetdir=${path}" /opt/module/datax/job/import/medical.$1.json
	
}
#3、根据表名匹配导数据
case $1 in
"all")
	load_data "dict"
	load_data "doctor"
	load_data "hospital"
	load_data "patient"
	load_data "user"
	load_data "medicine"
;;
"dict")
	load_data "dict"
;;
"doctor")
	load_data "doctor"
;;
"hospital")
	load_data "hospital"
;;
"patient")
	load_data "patient"
;;
"user")
	load_data "user"
;;
"medicine")
	load_data "medicine"
;;
*)
	echo "参数输入错误..."
;;
esac
